#include "Card.h"
#include "Game.h"

////////////////////////////
//Default Constructor
////////////////////////////
Card::Card()
{

}

////////////////////////////
//Constructor
//Idle position is (-100,-100)
///////////////////////////
Card::Card(ERANK _eRank, ESUIT _eSuit) 
	: GameObject(-100, -100, s_kiWidth, s_kiHeight), m_Rank(_eRank),
	  m_Suit(_eSuit),  m_bFaceUp(false), m_TableauPointsGiven(false),m_FoundationPointsGiven(false)
{
	m_bColorRed = (_eSuit == HEART || _eSuit == DIAMOND) ? true : false;
}

////////////////////////////
//Destructor
///////////////////////////
Card::~Card(void)
{
}

////////////////////////////
//Returns rank of card
///////////////////////////
int Card::GetRank() const
{
	return m_Rank;
}

////////////////////////////
//Returns suit of card
///////////////////////////
int Card::GetSuit() const
{
	return m_Suit;
}

////////////////////////////
//Flips the card to be face up or face down
///////////////////////////
void Card::Flip()
{
	m_bFaceUp = !m_bFaceUp;
}

////////////////////////////
//Returns true if the card is face up
///////////////////////////
bool Card::IsFaceUp() const
{
	return m_bFaceUp;
}

////////////////////////////
//Renders the card if it is faceup otherwise renders back of card
///////////////////////////
void Card::Draw()
{
	Game* _pGame = Game::GetGameInstance();
	if(_pGame)
	{
		if(m_bFaceUp)
		{
			m_hCurrentDC = m_hDCs[0];
			
		}
		else
		{
			m_hCurrentDC = m_hDCs[1];
		}
		BitBlt(_pGame->GetBackBuffer()->getDC(), m_Pos.x, m_Pos.y, Card::s_kiWidth, Card::s_kiHeight, GetHDC(), 0, 0, SRCCOPY);
		_pGame = nullptr;
	}
}
	
////////////////////////////
//Used in animations to reset the scene
///////////////////////////
void Card::UnDraw()
{
	Game* _pGame = Game::GetGameInstance();
	_pGame->GetBackBuffer()->Clear();
}

////////////////////////////
//Returns true of _rhs card has same rank and suit as *this
///////////////////////////
bool Card::operator==(const Card& _rhs)
{
	if(m_Rank == _rhs.GetRank() && m_Suit == _rhs.GetSuit())
	{
		return true;
	}
	else
	{
		return false;
	}
}

////////////////////////////
//1 is red, 0 is black. Used for comparisons
///////////////////////////
int Card::GetColour() const
{
	if(m_Suit == HEART || m_Suit == DIAMOND)
	{
		return 1;
	}
	else
	{
		return 0;
	}
}

////////////////////////////
//Card can no longer give points for being moved to tableau when this is called
///////////////////////////
void Card::SetTableauPointsGiven(bool _b)
{
	m_TableauPointsGiven = _b;
}

////////////////////////////
//Card can no longer give points for being moved to foundation when this is called
///////////////////////////
void Card::SetFoundationPointsGiven(bool _b)
{
	m_FoundationPointsGiven = _b;
}

////////////////////////////
//Returns whether points have been given for tableau
///////////////////////////
bool Card::GetTableauPointsGiven()
{
	return m_TableauPointsGiven;
}

////////////////////////////
//Returns whether points have been given for foundation
///////////////////////////
bool Card::GetFoundationPointsGiven()
{
	return m_FoundationPointsGiven;
}
